package com.wz.project.cxtj.viewstockdetail.controller;

import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.framework.web.page.TableDataInfo;
import com.wz.project.cxtj.viewstockdetail.domain.ViewStockDetailed;
import com.wz.project.cxtj.viewstockdetail.service.IViewStockDetailedService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 库存明细Controller
 * 
 * @author wz
 * @date 2022-05-18
 */
@Controller
@RequestMapping("/search/viewstockdetail")
public class ViewStockDetailedController extends BaseController
{
    private String prefix = "cxtj/viewstockdetail";

    @Autowired
    private IViewStockDetailedService viewStockDetailedService;

    @RequiresPermissions("search:viewstockdetail:view")
    @GetMapping()
    public String viewstockdetail()
    {
        return prefix + "/viewstockdetail";
    }

    /**
     * 查询库存明细列表
     */
//    @RequiresPermissions("search:viewstockdetail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ViewStockDetailed viewStockDetailed)
    {
        startPage();
        List<ViewStockDetailed> list = viewStockDetailedService.selectViewStockDetailedList(viewStockDetailed);
        return getDataTable(list);
    }

    /**
     * 导出库存明细列表
     */
    @RequiresPermissions("search:viewstockdetail:export")
    @Log(title = "库存明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ViewStockDetailed viewStockDetailed)
    {
        List<ViewStockDetailed> list = viewStockDetailedService.selectViewStockDetailedList(viewStockDetailed);
        ExcelUtil<ViewStockDetailed> util = new ExcelUtil<ViewStockDetailed>(ViewStockDetailed.class);
        return util.exportExcel(list, "viewstockdetail");
    }

    /**
     * 新增库存明细
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存库存明细
     */
    @RequiresPermissions("search:viewstockdetail:add")
    @Log(title = "库存明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ViewStockDetailed viewStockDetailed)
    {
        return toAjax(viewStockDetailedService.insertViewStockDetailed(viewStockDetailed));
    }

    /**
     * 修改库存明细
     */
    @GetMapping("/edit/{stockId}")
    public String edit(@PathVariable("stockId") String stockId, ModelMap mmap)
    {
        ViewStockDetailed viewStockDetailed = viewStockDetailedService.selectViewStockDetailedById(stockId);
        mmap.put("viewStockDetailed", viewStockDetailed);
        return prefix + "/edit";
    }

    /**
     * 修改保存库存明细
     */
    @RequiresPermissions("search:viewstockdetail:edit")
    @Log(title = "库存明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ViewStockDetailed viewStockDetailed)
    {
        return toAjax(viewStockDetailedService.updateViewStockDetailed(viewStockDetailed));
    }

    /**
     * 删除库存明细
     */
    @RequiresPermissions("search:viewstockdetail:remove")
    @Log(title = "库存明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(viewStockDetailedService.deleteViewStockDetailedByIds(ids));
    }
}
